package com.pine.manager.pineframework.convertors;

import com.pine.common.beans.pineframework.request.SysConfigQueryRequest;
import com.pine.common.beans.pineframework.request.SysConfigSaveOrUpdateRequest;
import com.pine.common.beans.pineframework.response.SysConfigQueryResponse;
import com.pine.common.convertor.EntityConvertor;
import com.pine.common.convertor.PoiConvertor;
import com.pine.common.convertor.QueryConvertor;
import com.pine.common.convertor.SaveConvertor;
import com.pine.dao.pineframework.constants.StatusEnum;
import com.pine.dao.pineframework.entity.SysConfig;
import com.pine.manager.pineframework.bo.SysConfigBo;
import com.pine.manager.pineframework.dto.SysConfigExportDto;
import com.pine.manager.pineframework.dto.SysConfigImportDto;
import com.pine.manager.pineframework.query.SysConfigQuery;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 系统配置表 转换器
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public abstract class SysConfigConvertor implements EntityConvertor<SysConfig, SysConfigBo>,
        QueryConvertor<SysConfigBo, SysConfigQuery, SysConfigQueryRequest, SysConfigQueryResponse>,
        SaveConvertor<SysConfigBo, SysConfigSaveOrUpdateRequest>,
        PoiConvertor<SysConfigBo, SysConfigImportDto, SysConfigExportDto> {

    @Override
    public abstract SysConfig entityBoToEntity(SysConfigBo sysConfigBo);

    @Override
    public abstract SysConfigBo entityToEntityBo(SysConfig sysConfig);

    @Override
    public abstract SysConfigQueryResponse entityBoToQueryResponse(SysConfigBo sysConfigBo);

    @Override
    public abstract SysConfigQuery queryRequestToQuery(SysConfigQueryRequest queryRequest);

    @Override
    public abstract List<SysConfig> entityBoToEntity(List<SysConfigBo> entityBo);

    @Override
    public abstract List<SysConfigBo> entityToEntityBo(List<SysConfig> entity);

    @Override
    public abstract SysConfigBo saveRequestToEntityBo(SysConfigSaveOrUpdateRequest saveRequest);



    @AfterMapping
    public void afterMappingEntityBoToEntity(@MappingTarget SysConfig sysConfig, SysConfigBo sysConfigBo) {
        // entityBoToEntity() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToEntity()
    }

    @AfterMapping
    public void afterMappingEntityToEntityBo(@MappingTarget SysConfigBo sysConfigBo, SysConfig sysConfig) {
        // entityToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityToEntityBo()
    }

    @AfterMapping
    public void afterMappingQueryRequestToQuery(@MappingTarget SysConfigQuery sysConfigQuery, SysConfigQueryRequest sysConfigQueryRequest) {
        // queryRequestToQuery() 内部其它代码执行完之后，最后会自动执行 afterMappingQueryRequestToQuery()
    }

    @AfterMapping
    public void afterMappingEntityBoToQueryResponse(@MappingTarget SysConfigQueryResponse sysConfigQueryResponse, SysConfigBo sysConfigBo) {
        // entityBoToQueryResponse() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToQueryResponse()
    }

    public StatusEnum integerToStatusEnum(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return StatusEnum.of(code);
    }

    public Integer statusEnumToInteger(StatusEnum statusEnum) {
        if (Objects.isNull(statusEnum)) {
            return null;
        }
        return statusEnum.getCode();
    }
}
